from typing import Union, List, Tuple
import subprocess
from logger.logger import quick_logger


class Command:
    @staticmethod
    def exec_command(command: Union[List, str], decode: str = 'GBK', timeout: int = 30) -> Tuple[int, str]:
        quick_logger.info(f'Executing command: {command}')
        process = subprocess.run(command, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.STDOUT,
                                 shell=True, timeout=timeout)
        return process.returncode, process.stdout.decode(decode)
